#include "control.h"
#include "game.h"

Control::Control():m_controlled(0)
{
}

Control::Control(Controllable* c):m_controlled(c)
{
}

Control::~Control()
{
  clear();
}

void Control::clear()
{
  actionIt it=m_actions.begin();
  for(;it!=m_actions.end();it++)
    delete(*it);

  m_actions.clear();
}

void Control::addAction(Action* action)
{
  m_actions.push_back(action);
}

void Control::delAction(Action* action)
{
  delete action;
  m_actions.remove(action);
}

void Control::logicTick()
{
  actionIt it=m_actions.begin();
  // Pasamos por todas las acciones
  for(;it!=m_actions.end();it++)
  {
    Sint32 magnitude=0;
    // y si el evento se ha producido se ejecuta la accion
    if(Game::self().getInputDevices().isEventTriggered(
          (*it)->getEvent(),magnitude))
    {
      m_controlled->doAction( (*it)->getActionID(), magnitude);
    }
  }
}
